package com.ruoyi.custservice.controller;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.base.yaml.BusinessConfig;
import com.ruoyi.bizsys.domain.ExtMonnifyReservedAccounts;
import com.ruoyi.bizsys.service.IExtMonnifyReservedAccountsService;
import com.ruoyi.bizsys.utils.BizConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author wqg
 * @description
 * @date 2022/6/24
 */
@Slf4j
@Api("iou财务还款接口")
@RestController
@RequestMapping("/business/extMonnifyReserved")
public class IouRepayFinanceController extends BaseController {

    @Autowired
    IExtMonnifyReservedAccountsService reservedAccountsService;

    @Autowired
    BusinessConfig businessConfig;

    private static RestTemplate restTemplate;
    static {
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        factory.setConnectTimeout(180000);
        factory.setReadTimeout(180000);
        restTemplate = new RestTemplate(factory);
    }

    /**
     * 查询客户减免订单记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:loan:loanlist')")
    @GetMapping("/list")
    public TableDataInfo ExtMonnifyReservedList(ExtMonnifyReservedAccounts ExtMonnifyReservedAccounts) {
        ExtMonnifyReservedAccounts.setStatus("ACTIVE");
        ExtMonnifyReservedAccounts.setState(BizConstants.BIZ_STATUS_1);
        startPage();
        List<ExtMonnifyReservedAccounts> list
                = reservedAccountsService.selectExtMonnifyReservedAccountsList(ExtMonnifyReservedAccounts);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('business:loan:loanlist')")
    @GetMapping("/doMonniflyFinance")
    public JSONObject doMonnifyFinance(String loanSerialNo, String accountReference) {
        log.info("doMonnifyFinance调用业务系统---");
        String url = businessConfig.getApiurl()+"/appTocustServer/doMonniflyFinance?loanSerialNo="+loanSerialNo+"&accountReference="+accountReference;
        JSONObject res = restTemplate.getForObject(url,JSONObject.class);
        return res;
    }

}
